<!DOCTYPE html>
<html lang="zh">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Document</title>
</head>
<body>
	<!-- 一次定时器 -->
	<button id="btn1">开启</button>
	<button id="btn2">清除</button>
	<script>
		// 定义变量，用于保存定时器
		var timer=null
		btn1.onclick = function() {
			// 开启
			timer = setTimeout(function(){
				console.log('hello')
			},3000)
		}
		btn2.onclick = function() {
			// 清除定时器
			clearTimeout(timer)
			alert('清除成功')
		}
	</script>
</body>
</html>